package com.xiaobao.campusLostFoundAfter.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xiaobao.campusLostFoundAfter.mapper.CategoryMapper;
import com.xiaobao.campusLostFoundAfter.pojo.Category;
import com.xiaobao.campusLostFoundAfter.service.CategoryService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 物品分类服务实现类
 */
@Service
public class CategoryServiceImpl implements CategoryService {

    private final CategoryMapper categoryMapper;

    public CategoryServiceImpl(CategoryMapper categoryMapper) {
        this.categoryMapper = categoryMapper;
    }

    @Override
    public List<Category> getAllCategories() {
        return categoryMapper.getAllCategories();
    }

    @Override
    public PageInfo<Category> getCategoryPage(int pageNum, int pageSize, String categoryName) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<>(categoryMapper.getCategoryList(categoryName));

    }

    @Override
    public Category getCategoryById(Integer id) {
        return categoryMapper.getCategoryById(id);
    }

    @Override
    public boolean addCategory(Category category) {
        return categoryMapper.addCategory(category) > 0;
    }

    @Override
    public boolean updateCategory(Category category) {
        return categoryMapper.updateCategory(category) > 0;
    }

    @Override
    public boolean deleteCategory(Integer id) {
        return categoryMapper.deleteCategory(id) > 0;
    }

    @Override
    public boolean batchDeleteCategories(List<Integer> ids) {
        return categoryMapper.batchDeleteCategories(ids) > 0;
    }


}
